package com.wwtech.epp.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wwtech.epp.R;

/**
 * Created by hu on 2017/9/1.
 */

public class ProjectMemberView extends LinearLayout {

    private int screenWidth;
    private int screenHeight;
    //头像
    private ImageView avaterImg;
    //昵称
    private TextView nickTextview;

    private boolean isSetInfo = false;

    public ProjectMemberView(Context context) {
        super(context);
        init(context);
    }

    public ProjectMemberView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ProjectMemberView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public void init(Context context) {
        setOrientation(LinearLayout.VERTICAL);
        setGravity(Gravity.CENTER);
        DisplayMetrics dm = new DisplayMetrics();
        dm = getResources().getDisplayMetrics();
        float density = dm.density; // 屏幕密度（像素比例：0.75/1.0/1.5/2.0）
        int densityDPI = dm.densityDpi; // 屏幕密度（每寸像素：120/160/240/320）
        screenWidth = dm.widthPixels; // 屏幕宽（像素，如：3200px）
        screenHeight = dm.heightPixels; // 屏幕高（像素，如：1280px）
        avaterImg = new ImageView(context);
        LinearLayout.LayoutParams lp = new LayoutParams(screenWidth / 10, screenWidth / 10);
        avaterImg.setLayoutParams(lp);
        avaterImg.setImageDrawable(getResources().getDrawable(R.mipmap.work_add));
        nickTextview = new TextView(context);
        LinearLayout.LayoutParams layoutParam = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        layoutParam.setMargins(0, 20, 0, 0);
        nickTextview.setLayoutParams(layoutParam);
        nickTextview.setTextSize(TypedValue.COMPLEX_UNIT_SP,12);
        nickTextview.setTextColor(context.getResources().getColor(R.color.color_333));
        nickTextview.setText("添加");
        nickTextview.setGravity(Gravity.CENTER);
        addView(avaterImg);
        addView(nickTextview);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(screenWidth / 5, screenWidth / 5);
    }

    public ImageView getAvaterImg() {
        return avaterImg;
    }

    public TextView getNickTextview() {
        return nickTextview;
    }

    public void setText(CharSequence content) {
        nickTextview.setText(content);
    }

    public boolean isSetInfo() {
        return isSetInfo;
    }

    public void setSetInfo(boolean setInfo) {
        isSetInfo = setInfo;
    }

    public void clear() {
        setSetInfo(false);
        nickTextview.setText("");
        avaterImg.setImageDrawable(getResources().getDrawable(R.mipmap.work_add));
    }
}
